package cn.nebula.music.controller;

import java.util.HashMap;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import cn.nebula.music.domain.Classification;
import cn.nebula.music.service.ClassificationService;
import cn.nebula.music.service.CombinationService;
import cn.nebula.music.service.SingerService;
import cn.nebula.music.service.SongService;

@Controller
public class ClassificationController {

	@Autowired
	private ClassificationService classificationService;

	@Autowired
	private SingerService singerService;

	@Autowired
	private SongService songService;

	@Autowired
	private CombinationService combinationService;

	@RequestMapping("/editClassification")
	@ResponseBody
	public Map<String, Object> editClassification(@RequestParam Integer id) throws Exception {
		Map<String, Object> values = new HashMap<String, Object>();
		values.put("classification", classificationService.findClassificationById(id));
		values.put("combinations", combinationService.findAllCombinationsOfBT());
		values.put("songs", songService.findAllSongsOfBT());
		values.put("singers", singerService.findAllSingersOfBT());
		return values;
	}

	@RequestMapping("/listAllClassifications")
	@ResponseBody
	public Map<String, Object> listAllClassifications() throws Exception {
		Map<String, Object> values = new HashMap<String, Object>();
		values.put("classifications", classificationService.findAllClassificationsOfBT());
		return values;
	}

	@RequestMapping("/newClassification")
	@ResponseBody
	public Map<String, Object> newClassification() throws Exception {
		Map<String, Object> values = new HashMap<String, Object>();
		values.put("combinations", combinationService.findAllCombinationsOfBT());
		values.put("songs", songService.findAllSongsOfBT());
		values.put("singers", singerService.findAllSingersOfBT());
		return values;
	}

	@RequestMapping("/updateClassification")
	@ResponseBody
	public boolean updateClassification(@RequestBody Classification classification) throws Exception {
		classificationService.updateClassification(classification);
		return true;
	}

	@RequestMapping("/addClassification")
	@ResponseBody
	public boolean addClassification(@RequestBody Classification classification) throws Exception {
		classificationService.addClassification(classification);
		return true;
	}

	@RequestMapping("/deleteClassification")
	@ResponseBody
	public boolean deleteClassification(@RequestParam Integer id) throws Exception {
		classificationService.deleteClassificationById(id);
		return true;
	}
}
